// 1.cpp

#include "exercise.h"

class exerciseScene1 : public exerciseScene
{
public:
    virtual void renderScene();
};

void exerciseScene1::renderScene()
{
    GLfloat interwined[] = 
    {
        1.0f, 0.2f, 1.0f, -1.0f, 1.0f, 1.0f,
        1.0f, 1.0f, 0.2f, -1.0f, -1.0f, 1.0f,
        0.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f,
        0.0f, 0.2f, 1.0f, 1.0f, 1.0f, 1.0f,
        1.0f, 1.0f, 0.2f, -1.0f, 1.0f, -1.0f,
        1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f,
        0.2f, 0.2f, 1.0f, 1.0f, -1.0f, -1.0f,
        1.0f, 1.0f, 0.2f, 1.0f, 1.0f, -1.0f
    };
    GLubyte frontIndices[] = {0, 1, 2, 3};
    GLubyte backIndices[] = {7, 6, 5, 4};
    GLubyte leftIndices[] = {4, 5, 1, 0};
    GLubyte rightIndices[] = {3, 2, 6, 7};
    GLubyte topIndices[] = {4, 0, 3, 7};
    GLubyte bottomIndices[] = {1, 5, 6, 2};

    glEnable(GL_DEPTH_TEST);

    glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    glColorPointer(3, GL_FLOAT, 6*sizeof(GLfloat), &interwined[0]);
    glVertexPointer(3, GL_FLOAT, 6*sizeof(GLfloat), &interwined[3]);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(1.0, 2.0, 2.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0);

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-4.0, 4.0, -4.0, 4.0, -10.0, 10.0);

    glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, frontIndices);
    glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, backIndices);
    glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, leftIndices);
    glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, rightIndices);
    glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, topIndices);
    glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, bottomIndices);
}

exerciseScene* createScene1()
{
    return new exerciseScene1;
}